< previous page page_548 next page >

Page 548
e10a6a0a59f035e870d90cca05b85fce.gif
    ' above the plane containing target.
    For i = 1 To NumPts
        ' Get the vector from plane to point.
        dx = Points(i).trans(1) - px
        dy = Points(i).trans(2) - py
        dz = Points(i).trans(3) - pz

        ' If the dot product < 0, the point is
        ' below the plane.
        If dx * nx + dy * ny + dz * nz < -0.01 Then
            IsAbove = False
            Exit Function
        End If
    Next i
    IsAbove = True
End Function
The Obscures Function
The Obscures function makes one final attempt to determine whether one polygon actually obscures another. First it compares each line segment in the first polygon with each segment in the second. If a segment in one polygon passes above a segment in the other, the function then compares the Z coordinate values of the two segments where they cross. If the first Z value is greater than the second, the function knows with certainty that the first polygon lies above the other. Similarly, if the second Z value is greater than the first, the second polygon must lie above the first.
If the two values are equal, the function continues to check other edges. If the routine later finds two edges that cross each other and have different Z values, it can determine which polygon is on top. If it finds no such edges, then the polygons probably do not overlap, but there are still two cases that the function needs to consider.
First, one polygon might completely surround the other. To check for this situation, function Obscures tests whether the projection of a point on the first polygon lies within the projection of the second. Because the edges of the polygons do not cross, if one point lies within the second polygon, they all do.
Remember that the IsAbove and IsBelow tests have already ruled out the possibility that the second polygon lies entirely above the plane of the first or that the first polygon lies entirely below the plane of the second. In that case, if the points in the first polygon lie within the projection of the second, parts of the second polygon must lie further from the center of projection than the first. In this case, the program needs to move the second polygon to the front of the list.
If there is still no overlap after this test, function Obscures determines whether a point in the second polygon lies within the projection of the first. If so, there is an overlap once again, and the program must move the second polygon to the front of the list.
The final odd situation that function Obscures does not handle is when one polygon has an edge that lies within the other polygon. If one polygon's edges enter and leave the other polygon only at vertices, the Z values where the edges cross are the same. In that

 
< previous page page_548 next page >